import React from 'react';
import LoadingContainer from './LoadingContainer';
import { addTopView, TopViewProps } from '../TopView';
let topProps: TopViewProps;
let isShowing = false;

function notice() {
	if (isShowing) return;
	isShowing = true;
	return new Promise(resolve => {
		addTopView(props => {
			topProps = props;
			return <LoadingContainer />
		}
		);
	});
}
const Loading = {
	show() {
		return notice();
	},

	hide() {
		if (topProps) {
			isShowing = false;
			topProps.destroy()
		}
	},
};

export default Loading
